package org.springframework.beans;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 山顶洞人郑某
 * @className PropertyValues.java
 * @date 2025 04 18  Bean的属性值集合
 */
public class PropertyValues {
    private final List<PropertyValue> propertyValueList = new ArrayList<>();


    /**
     * 添加配置值
     * @param pv
     */
    public void addPropertyValue(PropertyValue pv) {
        for (int i = 0; i < propertyValueList.size(); i++) {
            if (propertyValueList.get(i).getName().equals(pv.getName())) {
                propertyValueList.set(i, pv);
                return;
            }
        }
        propertyValueList.add(pv);
    }

    /**
     * 获取配置值数组
     * @return
     */
    public PropertyValue[] getPropertyValues() {
        return propertyValueList.toArray(new PropertyValue[0]);
    }

    public PropertyValue getPropertyValue(String porpertyName) {
        for (PropertyValue propertyValue : propertyValueList) {
            if (propertyValue.getName().equals(porpertyName)) {
                return propertyValue;
            }
        }
        return null;
    }
}
